package cn.wsalix.web;

import java.util.Map;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.stereotype.Controller;
import org.springframework.web.context.support.WebApplicationContextUtils;

import cn.wsalix.config.AppConfig;
import cn.wsalix.constant.Global;
import cn.wsalix.web.GlobalWeb;

/**
 * @author jskyme http://www.blogjava.net/Todd/archive/2009/09/15/295112.html
 */
public class WebInit implements ServletContextListener {

	public WebInit() {
		super();
	}

	GlobalWeb globalWeb = new GlobalWeb();

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		globalWeb.setSpringContext(WebApplicationContextUtils
				.getWebApplicationContext(sce.getServletContext()));
		Map<String, Object> annotationBeans = Global.springContext
				.getBeansWithAnnotation(Controller.class);
		AppConfig appConfig=GlobalWeb.appConfig;
		String appPath= sce.getServletContext().getContextPath();
		sce.getServletContext().setAttribute("sysConfig",GlobalWeb.sysConfig);
		sce.getServletContext().setAttribute("appConfig",GlobalWeb.appConfig);
		sce.getServletContext().setAttribute("nginxUrl",GlobalWeb.appConfig.getNginxUrl());
		sce.getServletContext().setAttribute("appPath",appPath);
		sce.getServletContext().setAttribute("appCssPath",
				appPath + "/theme/admin");
		sce.getServletContext().setAttribute("siteCssPath",
				appPath + "/theme/site");
		
		sce.getServletContext().setAttribute("templetDir",appConfig.getBackTheme());
		sce.getServletContext().setAttribute("siteTempletDir",appConfig.getFrontTheme());

	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {

	}

}
